package com.besttone.controller;

import com.besttone.dao.ImpalaJdbcClient;
import com.besttone.enums.EnumAPIResultCode;
import com.besttone.util.JsonUtil;
import com.besttone.util.MD5Util;
import com.besttone.vo.HangupSmsResultVO;
import com.besttone.vo.HangupSmsVO;
import com.besttone.vo.ResultVO;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by zhengzhenzhen on 2017/9/3.
 * 分页查询信令详情
 */
@RestController
@RequestMapping("/signal")
public class signalController {
    private static Log _log = LogFactory.getLog(HangupSmsController.class);
    private ResultVO resultVO=new ResultVO();
    @Autowired
    private Environment env;
    @RequestMapping("/{queryJson}")
    public String index(@PathVariable("queryJson") String queryJson)
    {
        _log.info("signal queryJson:"+queryJson);
        HangupSmsVO smsVO= JsonUtil.jsonStringToObject(queryJson, HangupSmsVO.class);
        StringBuffer pwdBuf=new StringBuffer();
        String nowpwd= MD5Util.md5(pwdBuf.append(smsVO.getStreaming_no()).append("&").append(smsVO.getSp_account())
                .append("&").append("sms").toString());//加密方式
        String current_page = StringUtils.isBlank(smsVO.getCurrent_page()) ? "1"
                : smsVO.getCurrent_page();// 当前页数
        String per_page_size = StringUtils.isBlank(smsVO.getPer_page_size()) ? "10"
                : smsVO.getPer_page_size();// 每页条数，默认10
        //order by必须写;limit后面为pageSize，offset后面为（currentPage-1）*pageSize
        int offset=(Integer.valueOf(current_page)-1)*Integer.valueOf(per_page_size);
        //String sql="select * from ti_signal_log where send_number='02022222222' and day_id<='20170503' and day_id>='20170410' order by day_id asc  limit  "+per_page_size+"  offset  " +offset;
        String sql="select * from ti_signal_log where day_id='20170901' order by day_id asc limit 10 offset 10;";
        List<HangupSmsResultVO> voList= ImpalaJdbcClient.queryHangupSmsByDay(sql);
        resultVO.setResult_code(EnumAPIResultCode.SUCCESS.getValue());
        resultVO.setResult_msg(JsonUtil.ObjectToJsonString(voList));
        return JsonUtil.ObjectToJsonString(resultVO);
    }
}
